package com.jxmcloud.business.cut.service.impl.database;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jxmcloud.business.cut.mapper.database.IUserDrawMoneyLogDBMapper;
import com.jxmcloud.business.cut.model.database.DBUserDrawMoneyLog;
import com.jxmcloud.business.cut.service.database.IUserDrawMoneyLogDBService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserDrawMoneyLogDBServiceImpl extends ServiceImpl<IUserDrawMoneyLogDBMapper, DBUserDrawMoneyLog> implements IUserDrawMoneyLogDBService {

    @Override
    public boolean insertData(DBUserDrawMoneyLog dbLog) {
        return this.baseMapper.insert(dbLog) == 1;
    }

    @Override
    public List<DBUserDrawMoneyLog> selectLastN(Integer uid, Integer n) {
        QueryWrapper<DBUserDrawMoneyLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uid", uid);
        queryWrapper.orderByDesc("id");
        queryWrapper.last("LIMIT " + n);
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<DBUserDrawMoneyLog> selectLastN(String account, Integer n) {
        QueryWrapper<DBUserDrawMoneyLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account", account);
        queryWrapper.orderByDesc("id");
        queryWrapper.last("LIMIT " + n);
        return this.baseMapper.selectList(queryWrapper);
    }

}
